import config from 'config'
import httpFetch from 'share/httpFetch'
import errorMessage from "share/errorMessage";

export default {

  //查询规则列表
  getRuleList(params) {
    return httpFetch.get(`${config.baseUrl}/api/expense/standard/rule/list`, params)
  },

  //新建或编辑规则
  newOrEditRule(params, setOfBooksId) {
    return httpFetch.post(`${config.baseUrl}/api/expense/standard/rule?setOfBooksId=${setOfBooksId}`, params)
  },

  //删除规则
  deleteRule(ruleOID) {
    return httpFetch.post(`${config.baseUrl}/api/expense/standard/rule/delete/${ruleOID}`)
  },

  //获取规则详情
  getRuleInfo(ruleOID) {
    return httpFetch.get(`${config.baseUrl}/api/expense/standard/master/rule/${ruleOID}`)
  },

  //获取规则的基本标准
  getStandardList(ruleOID, params) {
    return httpFetch.get(`${config.baseUrl}/api/expense/standard/master/item/${ruleOID}`, params)
  },

  //新建或编辑基本标准
  newOrEditStandard(params) {
    return httpFetch.post(`${config.baseUrl}/api/expense/standard/item`, params)
  },

  //删除基本标准
  deleteStandard(standardOID) {
    return httpFetch.post(`${config.baseUrl}/api/expense/standard/item/delete/${standardOID}`)
  },

  //获取管控信息
  getControlInfo(ruleOID) {
    return httpFetch.get(`${config.baseUrl}/api/expense/standard/master/controlitem/${ruleOID}`)
  },

  //更新管控信息
  updateControlInfo(ruleOID, params) {
    return httpFetch.post(`${config.baseUrl}/api/expense/standard/controlitem/${ruleOID}`, params)
  },

  //取消拆单配置
  cancelSplitProfile() {
    return httpFetch.put(`${config.baseUrl}/api/function/profiles/remove/splitProfile`)
  },
  //新增管控项
  saveControl(ruleOID,params){
    return httpFetch.post(`/api/expense/submit/control/item/${ruleOID}`,params)
      .catch(e => {
        errorMessage(e.response);
      })
  },
  //编辑管控项
  updateControl(ruleOID,params){
    return httpFetch.put(`/api/expense/submit/control/item/${ruleOID}`,params)
      .catch(e => {
        errorMessage(e.response);
      })
  },
  //删除管控项
  deleteControl(id) {
    return httpFetch.delete(`${config.baseUrl}/api/expense/submit/control/item/${id}`)
      .catch(e => {
        errorMessage(e.response);
        throw e;
      });
  },
  //根据项oid查询单个管控项
  searchControl(id) {
    return httpFetch.get(`${config.baseUrl}/api/expense/submit/control/item/${id}`)
      .catch(e => {
        errorMessage(e.response);
        throw e;
      });
  },
  //根据规则oid查询管控项列表
  searchControlList(id) {
    return httpFetch.get(`${config.baseUrl}/api/expense/submit/control/items/${id}`)
      .catch(e => {
        errorMessage(e.response);
        throw e;
      });
  }

}
